<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Item  extends CI_Controller{
  public function loadModel(){
    $this->load->model('item_model','item',TRUE);
    $this->load->model('category_model','category',TRUE);
  }
  public function create(){
    $this->loadModel();
    $param = $_POST;
    echo $this->item->create($param);
  }
  public function read($param=null){
    $this->loadModel();
    echo $this->item->read($param);
  }
  public function readWithCatId(){
    $this->loadModel();
    $param = $_POST;
    echo $this->item->readWCatId($param);
  }
  public function update(){
    $this->loadModel();
    //param = object
    $param = $_POST;
   echo $this->item->update($param);
  }
  public function delete(){
    $this->loadModel();
    //$param = id
    $param = $_POST;
    echo $this->item->delete($param);
  }
  function search(){
    $this->loadModel();
    $param = $_POST;
    //$param = array('name' => 'Test');
    $data['searchResult'] = json_decode($this->item->search($param));
    $data['allCategory'] = json_decode($this->category->readAll());
    $this->load->view('header');
    $this->load->view('searchResult', $data);
    $this->load->view('footer');
  }
  public function createItem(){
    $this->loadModel();
    $data['allCategory'] = json_decode($this->category->readAll());
    $this->load->view('header');
    $this->load->view('create_item',$data);
    $this->load->view('footer');
  }
  public function post($param = NULL){
    $this->loadModel();
    $data['post'] =  json_decode($this->item->publishedPost($param));
    $data['allCategory'] = json_decode($this->category->readAll());
    $this->load->view('header');
    $this->load->view('view_post',  $data);
    $this->load->view('footer');
  }
  
}